package com.aaa.boot.service.impl;

import com.aaa.boot.pojo.dto.AdminDTO;
import com.aaa.boot.mapper.AdminMapper;
import com.aaa.boot.service.AdminService;
import com.aaa.boot.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public AdminDTO loginPassword(String phone, String password) {
        AdminDTO adminInfo = adminMapper.login(phone, password);
        if(adminInfo == null){
            throw new RuntimeException("用户名或密码错误");
        }else if(adminInfo.getState() == 0){
            throw new RuntimeException("该用户已被禁用");
        }else if(adminInfo.getState() == 1){
            return adminInfo;
        }else {
            throw new RuntimeException("账号异常");
        }
    }

    @Override
    public AdminDTO loginCode(String phone, String code) {
        //验证码登录
        return null;
    }

    @Override
    public AjaxResult register(String userName,String phone, String password) {
        int result = adminMapper.register(userName, phone, password);
        if(result == 1){
            return AjaxResult.success("注册成功",result);
        }else {
            throw new RuntimeException("用户已存在");
        }
    }
}
